
var CommonValidate = {

	validate: 
		function (validate_item_id, validate_config) {
			
			configure = new CommonValidateConfigure(validate_config);
			
			var validate_item = validate_config[validate_item_id];
			
			if(validate_item == null) {
				CommonValidateUtil.log("error, validate_item is null");
				return;
			}
		
			var error_list = [];
				
			for(var i = 0; i < validate_item.length; i++) {
				var item = validate_item[i];
				var id = item.id;
				var descName = item.descName;
				var validate_func = item.validate_func;
				var advice_id = item.advice_id;
				if(advice_id == null) {
					advice_id = "advice_" + id;
				}
				
				this.clearError(advice_id, CommonValidateUtil);
				
				for(var j = 0; j < validate_func.length; j++) {
					
					var func = validate_func[j];
					
					var error_list = eval(func.func_name)(id, advice_id, descName, func.func_param, error_list, configure);
				}
			}
			
			if(error_list.length > 0) {
				this.displayError(error_list, CommonValidateUtil);
				return false;
			}
			return true;
		},
	
	displayError: 
		function (error_list, CommonValidateUtil) {

			for(var i = 0; i < error_list.length; i++) {
				var advice_id = error_list[i].advice_id;
				var error_msg = error_list[i].error_msg;
				
				var error_advice = CommonValidateUtil.c$(advice_id);
				if(error_advice == null) {
					CommonValidateUtil.log("there is no error_advice, id = " + advice_id);
					break;
				}
				error_advice.style.display = "block";
				
				var error_div = document.createElement("div");
				error_div.className = "errorItem";
				error_div.innerHTML = error_msg;
				
				error_advice.appendChild(error_div);
			}	
		},
		
	clearError: 
		function (advice_id, CommonValidateUtil) {
			if(CommonValidateUtil.c$(advice_id) != null) {
				
				CommonValidateUtil.c$(advice_id).innerHTML = "";
				CommonValidateUtil.c$(advice_id).style.display = "none";
				
			} else {
			
				CommonValidateUtil.log('error: you did not define advice id in page. advice_id = ' + advice_id);
			}
		}
};